<?php

namespace app\admin\controller;

use app\common\model\News as NewsModel;
/**
 * 每日一禅控制器
 * Class DailyMeditation
 * @package app\index\controller
 */
class DailyMeditation extends Base
{
    /**
     * [index  获取每日一禅列表]
     * @return mixed
     * @author [C.]
     */
    public function getIndex()
    {
        $model = new NewsModel();
        $param = input('param.');
        $this->getPageAndSize($param);
        $map = [];
        $user = $this->user;
        try{
            if (is_array($param)) {
                if (!empty($param['con']))
                    $map['title'] = ['like', "%" . $param['con'] . "%"];

                if(!empty($param['start']) && !empty($param['end'])){
                    $map['addtime'] = ['between',[strtotime($param['start']),strtotime($param['end'])]];
                }
            }
            $map['states'] = ['neq',-1];
            $map['cateid'] = 7;
            $fields = 'id,cover,addtime,content,states,read_num,jread_num,from,share_top,share_buttom';
            $count = $model->getCounts($map);//满足条件的总数
            $allpage = intval(ceil($count / $this->size));//总页数
            $lists = $model->getlists($map,$this->from, $this->size,$fields);
            foreach($lists as $k=>$v){
                $http = substr($v['cover'],0,4);
                if($http != 'http'){
                    $lists[$k]['cover'] = config('domain_name').$v['cover'];
                }
                $lists[$k]['content'] = percent1($v['content']);
                $lists[$k]['addtime'] = date('Y-m-d H:i:s',$lists[$k]['addtime']);
                $lists[$k]['cname'] = '每日一禅';
            }
        }catch(\Exception $e){
            return admin_json(-1, '获取失败'.$e->getMessage());
        }
        writelog('查看每日一禅列表', 1,$user);
        return admin_json(1, '获取成功',[
            'count' => $count,//总记录数
            'allpage' => $allpage,  //总页数
            'lists' => $lists,  //列表数据
        ]);
    }
}